package exchange

import (
	"global/libs/structs"
	"global/core"
	"github.com/parnurzeal/gorequest"
)

type KlineInterface interface {
	Init(ctx *core.Context, slug string) error
	Run()
}

type BaseKline struct {
	ctx 		*core.Context
	slug 		string
	symbols 	[]structs.Symbol
	// client 		*gorequest.SuperAgent
}

func (k *BaseKline) init(ctx *core.Context, slug string) {
	k.ctx = ctx
	k.slug = slug
	// k.client = gorequest.New()
}

func (k *BaseKline) loadSymbols() error {
	conn := k.ctx.GetBaseRedis().Get()
	defer conn.Close()
	var err error
	k.symbols, err = core.GetSymbolsByExchange(conn, k.slug)
	if err != nil {
		return err
	}
	return nil
}

func (k *BaseKline) get(uri string, data interface{}) ([]byte, error) {
	client := gorequest.New()
	_, body, errs := client.Get(uri).
		Query(data).
		Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36").
		Set("Content-Type", "application/x-www-form-urlencoded").
		End()
	if len(errs) > 0 {
		return nil, errs[0]
	}
	return []byte(body), nil
}